home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 11 / AMUG BBS in a Box Volume XI (April 1994) (MacWizards).iso / Files / QuickTime / QT Tools / QuickTime Interfacing.sit / QuickTime Interfacing / SeeMovieRun folder / sources / CQTDoc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-29  |  7.3 KB  |  310 lines  |  [TEXT/KAHL]

  1. /****
  2.  * CQTDoc.c
  3.  *
  4.  *    Document methods for the QuickTime Demo application.
  5.  *
  6.  *  Copyright © 1992 Joe Zobkiw.  All rights reserved.
  7.  *  Portions Copyright © 1990 Symantec Corporation.  All rights reserved.
  8.  *
  9.  *    This document method doesn't deal with files all that much
  10.  *    since we are a very simple demo.
  11.  *
  12.  ****/
  13.  
  14. #include "Global.h"
  15. #include "Commands.h"
  16. #include "CApplication.h"
  17. #include "CBartender.h"
  18. #include "CDataFile.h"
  19. #include "CDecorator.h"
  20. #include "CDesktop.h"
  21. #include "CError.h"
  22. #include "CPanorama.h"
  23. #include "CScrollPane.h"
  24. #include "CQTDoc.h"
  25. #include "CQTPane.h"
  26. #include "TBUtilities.h"
  27. #include "CWindow.h"
  28. #include <Packages.h>
  29. #include "QuickTime Utilities.h"
  30. #include "Defines.h"
  31.  
  32. #define    WINDQT        500        /* Resource ID for WIND template */
  33.  
  34. extern    CBartender    *gBartender;    /* The menu handling object */
  35. extern    CDecorator    *gDecorator;    /* Window dressing object    */
  36. extern    CDesktop    *gDesktop;        /* The enclosure for all windows */
  37.  
  38. /***
  39.  * IQTDoc
  40.  *
  41.  *    This is your document's initialization method.
  42.  *    If your document has its own instance variables, initialize
  43.  *    them here.
  44.  *
  45.  *    The least you need to do is invoke the default method.
  46.  *
  47.  ***/
  48.  
  49.  
  50. void CQTDoc::IQTDoc(CApplication *aSupervisor, Boolean printable)
  51.  
  52. {
  53.     CDocument::IDocument(aSupervisor, printable);
  54. }
  55.  
  56.  
  57. /***
  58.  * Dispose
  59.  *
  60.  *    This is your document's destruction method.
  61.  *    If you allocated memory in your initialization method
  62.  *    or opened temporary files, this is the place to release them.
  63.  *
  64.  *    Be sure to call the default method!
  65.  *
  66.  ***/
  67.  
  68. void CQTDoc::Dispose()
  69.  
  70. {
  71.     inherited::Dispose();
  72. }
  73.  
  74.  
  75. /***
  76.  * DoCommand
  77.  *
  78.  *    This is the heart of your document.
  79.  *    In this method, you handle all the commands your document
  80.  *    deals with.
  81.  *
  82.  ***/
  83.  
  84. void CQTDoc::DoCommand(long theCommand)
  85.  
  86. {
  87.     switch (theCommand) {
  88.     
  89.         case kImportMovieItem: {
  90.             FSSpec    spec;
  91.             if (GetMovieFileFSSpec(&spec)) {
  92.                 ((CQTPane*)itsMainPane)->ImportMovie(&spec);
  93.                 itsWindow->SetTitle(spec.name);
  94.             }
  95.         }
  96.         break;
  97.             
  98.         default:    inherited::DoCommand(theCommand);
  99.                     break;
  100.     }
  101. }
  102.  
  103.  
  104. /***
  105.  * UpdateMenus
  106.  *
  107.  *  In this method you can enable menu commands that apply when
  108.  *  your document is active.
  109.  *
  110.  *  Be sure to call the inherited method to get the default behavior.
  111.  *  The inherited method enables these commands: cmdClose, cmdSaveAs,
  112.  *  cmdSave, cmdRevert, cmdPageSetup, cmdPrint, cmdUndo.
  113.  *
  114. ***/
  115.  
  116.  void CQTDoc::UpdateMenus()
  117.  
  118.  {
  119.   inherited::UpdateMenus();
  120.  
  121.     /* Enable your menu commands here (enable each one with a call to   
  122.        gBartender->EnableCmd(command_number)).  
  123.     */              
  124.    
  125.    gBartender->EnableCmd(kImportMovieItem);  
  126.  }
  127.  
  128. /***
  129.  * NewFile
  130.  *
  131.  *    When the user chooses New from the File menu, the CreateDocument()
  132.  *    method in your Application class will send a newly created document
  133.  *    this message. This method needs to create a new window, ready to
  134.  *    work on a new document.
  135.  *
  136.  *    Since this method and the OpenFile() method share the code for creating
  137.  *    the window, you should use an auxiliary window-building method.
  138.  *
  139.  ***/
  140. void CQTDoc::NewFile(void)
  141.  
  142. {    
  143.     Str255  wTitle;     /* Window title string.         */
  144.     short   wCount;     /* Index number of new window.  */
  145.     Str255  wNumber;    /* Index number as a string.    */
  146.     
  147.     BuildWindow(NULL);    // we have no spec here.
  148.     
  149.         /**
  150.          ** Append an index number to the
  151.          ** default name of the window.
  152.          **/
  153.          
  154.     itsWindow->GetTitle(wTitle);
  155.     wCount = gDecorator->GetWCount();
  156.     NumToString(wCount, wNumber);
  157.     ConcatPStrings(wTitle, (StringPtr) "\p ");
  158.     ConcatPStrings(wTitle, wNumber);
  159.     itsWindow->SetTitle(wTitle);
  160.     itsWindow->Select();
  161. }
  162.  
  163. /***
  164.  * OpenQTFile
  165.  *
  166.  * Opens the movie file into a window
  167.  *
  168.  ***/
  169.  
  170. void CQTDoc::OpenQTFile(FSSpec    *movieSpec)
  171. {
  172.     BuildWindow(movieSpec);
  173.     itsWindow->SetTitle(movieSpec->name);
  174.     itsWindow->Select();
  175. }
  176.  
  177. /***
  178.  * BuildWindow
  179.  *
  180.  *    This is the auxiliary window-building method that the
  181.  *    NewFile() and OpenFile() methods use to create a window.
  182.  *
  183.  *    In this implementation, the argument is the data to display.
  184.  *
  185.  ***/
  186.  
  187. void CQTDoc::BuildWindow (FSSpec *movieSpec)
  188.  
  189. {
  190.     CScrollPane        *theScrollPane;
  191.     CQTPane            *theMainPane;
  192.  
  193.         /**
  194.          **    First create the window and initialize
  195.          **    it. The first argument is the resource ID
  196.          **    of the window. The second argument specifies
  197.          **    whether the window is a floating window.
  198.          **    The third argument is the window's enclosure; it
  199.          **    should always be gDesktop. The last argument is
  200.          **    the window's supervisor in the Chain of Command;
  201.          **    it should always be the Document object.
  202.          **
  203.          **/
  204.  
  205.     itsWindow = new(CWindow);
  206.     itsWindow->IWindow(WINDQT, FALSE, gDesktop, this);
  207.     
  208.         /**
  209.          **    After you create the window, you can use the
  210.          **    SetSizeRect() message to set the window’s maximum
  211.          **    and minimum size. Be sure to set the max & min
  212.          **    BEFORE you send a PlaceNewWindow() message to the
  213.          **    decorator.
  214.          **
  215.          ** The default minimum is 100 by 100 pixels. The
  216.          **    default maximum is the bounds of GrayRgn() (The
  217.          **    entire display area on all screens.)
  218.          **
  219.          ** We'll use the defaults.
  220.          **
  221.          **/
  222.     
  223.         /**
  224.          ** Our window will contain a ScrollPane,
  225.          ** which in turn will contain a Panorama.
  226.          ** Now, let's create the ScrollPane.
  227.          **/
  228.  
  229.     theScrollPane = new(CScrollPane);
  230.     
  231.         /**
  232.          **    You can initialize a scroll pane two ways:
  233.          **        1. You can specify all the values
  234.          **           right in your code, like this.
  235.          **        2. You can create a ScPn resource and
  236.          **           initialize the pane from the information
  237.          **           in the resource.
  238.          **
  239.          **/
  240.  
  241.     theScrollPane->IScrollPane(itsWindow, this, 10, 10, 0, 0,
  242.                                 sizELASTIC, sizELASTIC,
  243.                                 TRUE, TRUE, TRUE);
  244.  
  245.         /**
  246.          **    The FitToEnclFrame() method makes the
  247.          **    scroll pane be as large as its enclosure.
  248.          **    In this case, the enclosure is the window,
  249.          **    so the scroll pane will take up the entire
  250.          **    window.
  251.          **
  252.          **/
  253.  
  254.     theScrollPane->FitToEnclFrame(TRUE, TRUE);
  255.  
  256.  
  257.         /**
  258.          **    itsMainPane is the document's focus
  259.          **    of attention. Some of the standard
  260.          **    classes (particularly CPrinter) rely
  261.          **    on itsMainPane pointing to the main
  262.          **    pane of your window.
  263.          **
  264.          **    itsGopher specifies which object
  265.          ** should become the gopher when the document
  266.          ** becomes active. By default
  267.          **    the document becomes the gopher. It’s
  268.          **    likely that your main pane handles commands
  269.          **    so you’ll almost always want to set itsGopher
  270.          **    to point to the same object as itsMainPane.
  271.          **
  272.          **    Note that the main pane is the
  273.          **    panorama in the scroll pane and not
  274.          **    the scroll pane itself.
  275.          **
  276.          **/
  277.  
  278.     theMainPane = new(CQTPane);
  279.     theMainPane->IQTPane(theScrollPane, this, 0, 0, 0, 0, sizELASTIC, sizELASTIC, movieSpec);
  280.     itsMainPane = theMainPane;
  281.     itsGopher = theMainPane;
  282.     
  283.         /**    The FitToEnclosure() method makes the pane
  284.          **    fit inside the enclosure. The inside (or
  285.          **    interior) of a scroll pane is defined as
  286.          **    the area inside the scroll bars.
  287.          **/
  288.  
  289.     theMainPane->FitToEnclosure(TRUE, TRUE);
  290.  
  291.         /**
  292.          **    Send the scroll pane an InstallPanorama()
  293.          ** message to associate the panorama with 
  294.          ** the scroll pane.
  295.          **
  296.          **/
  297.  
  298.     theScrollPane->InstallPanorama(theMainPane);
  299.     
  300.         /**
  301.          **    The Decorator is a global object that takes care
  302.          **    of placing and sizing windows on the screen.
  303.          **    You don't have to use it.
  304.          **
  305.          **/
  306.  
  307.     gDecorator->PlaceNewWindow(itsWindow);
  308. }
  309.  
  310.